package com.atguigu.eduservice.controller.front;

import com.atguigu.com.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class EnuIndexController {

    @Autowired
    private EduTeacherService eduTeacherService;
    @Autowired
    private EduCourseService eduCourseService;
    //查询8条课程记录 和4条讲师记录
    @GetMapping("index")
    public R index(){
        //4条讲师记录前
        QueryWrapper<EduTeacher> teacherWapper = new QueryWrapper<>();
        teacherWapper.orderByDesc("id");
        teacherWapper.last("limit 4");
        List<EduTeacher> teacherList = eduTeacherService.list(teacherWapper);


        //查询8条课程记录 前
        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("id");
        courseQueryWrapper.last("limit 8");
        List<EduCourse> courseList = eduCourseService.list(courseQueryWrapper);

        return R.ok().data("teacherList",teacherList).data("courseList",courseList);
    }
}
